package com.hardy.leetcode;

/**
 * User: Ruijie Date: 2016/9/2
 */
public class MergeSortedArray {
    public static void merge(int A[], int m, int B[], int n) {
        int[] C=new int[m+n];
        int i=0;
        int j=0;
        int k=0;
        while(i<m&&j<n){
            if(A[i]>B[j]){
                C[k++]=B[j++];
            }else{
                C[k++]=A[i++];
            }
        }
        while(i<m){
            C[k++]=A[i++];
        }
        while(j<n){
            C[k++]=B[j++];
        }
        for(int q=0;q<C.length;q++){
            A[q]=C[q];
        }
    }

    public static void main(String[] args) {
        int[] A={1,3,5,7,9};
        int[] B={2,4,6,8,10};
        merge(A,A.length,B,B.length);
        for(int i=0;i<A.length;i++){
            System.out.print(A[i]+" ");
        }
    }
    public static void printArray(int[] array){
        for(int i=0;i<array.length;i++){
            System.out.print(array[i]+" ");
        }
    }
}
